<template>
  <div class="card">
    <van-row type="flex" class="content">
      <van-col span="4" offset="1">
        <van-image fit="cover" round width="4rem" height="4rem" :src="headSrc" />
      </van-col>
      <van-col span="19">
        <van-row type="flex">
          <van-col offset="1">
            <span>{{ "你好，" + userName + "（" + deptName + "）" }}</span>
          </van-col>
        </van-row>
        <van-row type="flex">
          <van-col offset="1">
            <span>{{ dateInfo }}</span>
          </van-col>
        </van-row>
      </van-col>
    </van-row>
  </div>
</template>
<script>
import tools from "../../../tools/tools";
import comm from "../../../tools/comm";
import api from "../../../tools/api";
import ui from "../../../tools/ui";

export default {
  data() {
    return {
      userName: "",
      dateInfo: "",
      deptName: "",
      headSrc: "",
    };
  },
  computed: {
    weekDay() {
      let week = tools.moment().format("E");
      let r = "";
      switch (parseInt(week)) {
        case 1:
          r = "星期一";
          break;
        case 2:
          r = "星期二";
          break;
        case 3:
          r = "星期三";
          break;
        case 4:
          r = "星期四";
          break;
        case 5:
          r = "星期五";
          break;
        case 6:
          r = "星期六";
          break;
        case 7:
          r = "星期日";
          break;
      }
      return r;
    },
  },
  mounted() {
    // let userInfo = JSON.parse(tools.getLocalData(comm.USERINFO));
    // this.userName = userInfo.name;
    // this.deptName = userInfo.dept.name;
    // let date = tools.moment().format("YYYY-MM-DD");
    // this.dateInfo = date + " " + this.weekDay;
    // this.headSrc = tools.getLocalData(comm.APP_RES_URL) + "icon/famale.jpg";
    this.getUserInfo();
  },
  methods: {
    getUserInfo() {
      let self = this
      ui.showLoading();
      api.ajax(
        {
          methodName: "app/getInfo",
          s(code, res) {
            tools.logToStr("code=" + code);
            tools.logToStr("getInfo res=" + res);
            let userInfo = res.user
            tools.setLocalData(comm.USERINFO,JSON.stringify(userInfo));
            self.userName = userInfo.nickName;
            self.deptName = userInfo.dept.deptName;
            let date = tools.moment().format("YYYY-MM-DD");
            self.dateInfo = date + " " + self.weekDay;
            self.headSrc = comm.apiUrl() + userInfo.avatar;
            tools.logToStr("img = "+self.headSrc)
            ui.hideLoading();
          },
        });
    },
  },
};
</script>
<style scoped>
.card {
  width: 100vw;
  height: 100px;
  background: #4a90e2;
}
.card span {
  color: white;
  font-size: 16px;
}
.content {
  padding-top: 15px;
  align-items: center; 
}
</style>
